/**
 * @file AddLayerCommand.cpp
 *
 * @date 29/12/2011
 * @author Tales 
 *
 */

#include "AddLayerCommand.hpp"
#include "../common/Color.hpp"
#include "PictureState.hpp"

namespace yep
{

AddLayerCommand::AddLayerCommand(int pos, SDL_Surface *src) :
		Command(Color::BLACK, pos)
{
	position = pos;
	source = src;
}

void AddLayerCommand::execute(PictureState & state)
{
	if (source)
		state.addLayer(source);
	else
		state.addLayer();
	if(position >=0)
	{
		const int max = state.getLayerCount();
		for (int i = max - 1; i > position; --i)
		{
			state.swap(i, i-1);
		}
	}
}

} /* namespace yep */
